package com.xw.config;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;
import java.sql.SQLSyntaxErrorException;


/**
 * @author 小五
 *
 * 全局异常处理
 */

@RestControllerAdvice
@RestController
public class GlobalExceptionHandler {

//    @ExceptionHandler(Exception.class)
//    public  void ExceptionHandler(Exception e){
//        String message = e.getMessage();
//        System.out.println("出现异常,原因是：" + message);
//        e.printStackTrace();
//
//    }

    @ExceptionHandler(ArithmeticException.class)
    public  void ExceptionHandler1(Exception e){
        String message = e.getMessage();
        System.out.println("出现算数异常异常,原因是：");
        e.printStackTrace();
    }


    @ExceptionHandler(SQLSyntaxErrorException.class)
    public  void ExceptionHandler3(Exception e){
        String message = e.getMessage();
        System.out.println("SQL语句异常,原因是：");
        e.printStackTrace();
    }


}
